<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>promise-ajax</title>
  <script src="./js/jquery.js"></script>
  <script>
    const baseURL = 'http://47.94.46.113:8888';
    const promise = new Promise((resolve, reject) => {
      // 异步请求
      $.ajax({
        url: baseURL + '/index/category/findAlll',
        method: 'get',
        success(res) {
          // 异步请求成功，将成功结果作为实参传递到resolve回调中去
          resolve(res);
        },
        error(error) {
          // 异步请求失败，将失败结果作为实参传递到reject回调中去
          reject(error);
        }
      })
    })
    // 监听promise实例状态的改变
    promise.then((res) => {
      console.table(res.data);
    }).catch((error) => {
      console.error(error);
    }).finally(() => {
      console.log('最终执行');
    })
  </script>
</head>

<body>

</body>

</html>